/**
 * Created by Laggo on 15/12/24.
 */
app.service('lineOrderService', ['$q', 'ajax', 'lineCustomService', function ($q, ajax, lineCustomService) {
    //数组按三个等分
    function sliceThree(arr){
        var newArr = [];
        for(var i = 0,length= arr.length; i<length; i++){
            var q = Math.floor(i/3);
            if(!newArr[q]){
                newArr[q]=[];
            }
            newArr[q].push(arr[i]);
        }
        return newArr;
    }

    var isArr='';
    this.detail = function (id) {
        var defer = $q.defer();
        var promise = defer.promise;
        if(id.orderArr==''){
            id=id.id
            isArr=false;
        }
        else{
            id=id.orderArr
            isArr=true;
        }
        var deferred = $q.defer();
            //包含的商品
            ajax.get({
                url: '/back/order/printOrderDetail',
                data: {
                    orderId_in: id
                },
            }).then(function (result) {
                result.halfOrder.forEach(function(item){
                    item.listOrderDetail.length = 33;
                    item.listOrderDetail = sliceThree(item.listOrderDetail);
                })
                result.wholeOrder.forEach(function(item){
                    item.listOrderDetail.length = 99;
                    item.listOrderDetail = sliceThree(item.listOrderDetail);
                })
                result.thanOrder.forEach(function(item){
                    item.listOrderDetail = sliceThree(item.listOrderDetail);
                })
                defer.resolve(result);
            })

        return promise;
    }
}])